# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
### Reducing Prejudice and Support for Religious 
### Nationalism Through Conversations on WhatsApp 

### Author: Rajeshwari Majumdar
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# File:     results_prejudice.R
# Purpose:  analyze prejudice outcome (feelings about Muslims); 
#           produce Tables 2, D.10, and D.11
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# Load data and custom functions 
rm(list=ls())
load("data/Completes_Merged_Anonymized.RData")
source("code/02_setup_functions.R")

# %%%%%%%%%%%%%%%%%%%%%%%%%%
# Main text ----
# %%%%%%%%%%%%%%%%%%%%%%%%%%

## Baseline descriptive information ----
### Average response about different religious groups among Hindus
d %>% filter(religion == "Hindu") %>% select(feelth_muslim, feelth_hindu, feelth_christian) %>% summary()
### Proportion of negative/very negative responses about different religious groups among Hindus
d %>% filter(religion == "Hindu") %>% select(feelth_muslim, feelth_hindu, feelth_christian) %>% summarize(across(everything(), ~ mean(.x < 3)))


## Table 2: Effect of treatment on feelings about Muslims ----
### First panel: One day later
fn_reg_main(depvar = "post.feelth_muslim", data = d)
### Second panel: Two weeks later
fn_reg_main(depvar = "follow.feelth_muslim", data = d)


## Effect sizes ----
### Calculate Cohen's d for overall effect 
fn_effectsize(depvar = "post.feelth_muslim", topic = "all", data = d)
### Calculate Cohen's d within the non-political topic condition
#### one day post-treatment
fn_effectsize(depvar = "post.feelth_muslim", topic = "non", data = d)
#### two weeks post-treatment
fn_effectsize(depvar = "follow.feelth_muslim", topic = "non", data = d)

# %%%%%%%%%%%%%%%%%%%%%%%%%%
# Appendix ----
# %%%%%%%%%%%%%%%%%%%%%%%%%%

## Table D.10: Effect of treatment on short-term feelings about Muslims (between-and-within-subjects analysis) ----
d$post_pre.feelth_muslim = d$post.feelth_muslim - d$feelth_muslim
fn_reg_main(depvar = "post_pre.feelth_muslim", data = d)


## Table D.11: Effect of treatment on feelings about Muslims (six-level treatment variable) ----
fn_reg_sixer(depvars = c("post.feelth_muslim","follow.feelth_muslim"),
               depvars_names = c("One day post-treatment", "Two weeks post-treatment"),
               data = d)
